﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>企业员工记录</title>
    <!--link to style-->
    <link rel="stylesheet" href="css/adapt.css" />
    <link rel="stylesheet" href="../css/bootstrap.min.css" />
    <link rel="stylesheet" href="../css/font-awesome.min.css" />
    <!--<link rel="stylesheet" href="css/adapt.css" />--> 
    <!--//End link to style-->
    <script type="text/javascript" src="../js/jquery.js"></script>
</head>
<body>
    <div class="Body clearfix">
       <div class="catlog">
           <span class="cat_block">当前位置</span>
           <span class="cat_block icon-chevron-right">员工记录</span>
           <span class="cat_block icon-chevron-right">查看所有员工记录</span>
       </div>
        <!--new construction Start-->
        <div class="searchBarOut">
            <div class="searchBarPad">
                <div class="searchBarTit">
                    按条件查询
                </div>
                <div class="searchAreaOut">
                    <div class="searchAreaBlock">
                        <input class="nameSear textbar" type="text" name="nameSear" tag="nameSear" />
                        <span class="SearchButton" id="nameSear" tag="nameSear">姓名筛选</span>
                    </div>
                    <div class="searchAreaBlock">
                        <input class="noSear textbar" type="text" name="noSear" tag="noSear" />
                        <span class="SearchButton" id="noSear" tag="noSear" >员号筛选</span>
                    </div>

                </div>
            </div>
        </div>
        <!--End new construction-->

      <table class="table">
          <tr class="fir_tit">
              <td class="firline">员工号</td>
              <td class="firline">姓名</td>
              <td class="firline">生日</td>
              <td class="firline">性别</td>
              <td class="firline">政治面貌</td>
              <td class="firline">学历</td>
              <td class="firline">民族</td>
              <td class="firline">手机号</td>
              <td class="firline">所属部门</td>
              <td class="firline">薪资</td>
              <td class="firline">在职状态</td>
              <td class="firline">操作</td>
          </tr>
          <!--  
          <tr class="lineTr">
              <td class="reguLine noSear">001</td>
              <td class="reguLine nameSear">admin</td>
              <td class="reguLine">22</td>
              <td class="reguLine">female</td>
              <td class="reguLine">citizen</td>
              <td class="reguLine">bachelor</td>
              <td class="reguLine">han</td>
              <td class="reguLine">18915418643</td>
              <td class="reguLine">tech</td>
              <td class="reguLine">00000<a href="resetSalary.html"><span class="icon-pencil span"></span></a></td>
              <td class="reguLine">在职<a href="resetStatus.html"><span class="icon-pencil span"></span></a></td>
              <td class="reguLine"><a href="resetStaffInfo.html"><span class="icon-pencil span"></span></a><span class="icon-trash span"></span></td>
          </tr>
         -->
 
      </table>

    </div>

   

    <script>
    	var departstr = '';
        $(function () {
        	$.ajax({
                type: "Post",
                url: "/hr_doc/servlet/DepartServlet",
                data: {
               	 Command:"list"
                },
                async: false,
                dataType: "json",
                success: function (d) {
					console.log(d);
	               	if(d.code == 1){
	               		departstr = d.result;
	               	}
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                	
                }
            });
        	
        	console.log(1);
            /*loading record of staff*/
			$.ajax({
                type: "Post",
                url: "/hr_doc/servlet/StaffServlet",
                data: {
               	 Command:"list"
                },
                async: false,
                dataType: "json",
                success: function (d) {
					console.log(d);
	               	if(d.code == 1){
	               		var result = d.result;
	               		var str = "";
	               		for(var i = 0;i<result.length;i++){
	               			var item = result[i];
	               			str +='<tr class="lineTr">';
	               			str += '<td class="reguLine noSear">'+item.sno+'</td>';
	               			str += '<td class="reguLine nameSear">'+item.sname+'</td>';
	                        str += '<td class="reguLine">'+item.sbirthday+'</td>';
	                        str += '<td class="reguLine">'+item.ssex+'</td>';
	                        str += '<td class="reguLine">'+item.spolitic+'</td>';
	                        str += '<td class="reguLine">'+item.seducat+'</td>';
	                        str += '<td class="reguLine">'+item.snation+'</td>';
	                        str += '<td class="reguLine">'+item.sphone+'</td>';
	                        str += '<td class="reguLine">'+item.sdepartname+'</td>';
	                        str += '<td class="reguLine">'+item.sminsalary+'<a href='+item.id+'"resetSalary.html?id="><span class="icon-pencil span "></span></a></td>';
	                        var statusname = '';
	                        switch(item.sstatus){
	                        case 0:
	                        	statusname = '在职';
	                        	break;
	                        case 1:
	                        	statusname = '离职';
	                        	break;
	                        case 2:
	                        	statusname = '退休';
	                        	break;
	                        case 3:
	                        	statusname = '停职';
	                        	break;
	                        case 4:
	                        	statusname = '休假';
	                        	break;
	                       default:
	                        	statusname = '未知';
	                        	break;
	                        }
	                        
	                        str += '<td class="reguLine">'+statusname+'<a href='+item.id+'"resetStatus.html?id="><span class="icon-pencil span"></span></a></td>';
	                        
	                        str += '<td class="reguLine"><a href='+item.id+'"resetStaff.html?id="><span class="icon-pencil span"></span></a><span class="icon-trash span" onclick="deleteSta('+item.id+')"></span></td>';
	                    	str += '</tr>';
	               		}
	               		$(".table").append(str);
	               		
	               	}
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                	
                }
			});
            /*after succeed the loading*/
            //namSearch bar function
			$("#nameSear").click(function () {
			    var textbar = $(this).siblings($(".textbar")).val();
			    /*succeed get value*/
			    console.log(textbar);
			    var nameBlock = $(".lineTr").children($(".nameSear"));
			    console.log($(nameBlock).text());
			    console.log($(nameBlock).html());
			    for (var i = 0; i < $(".lineTr").length ; i++) {
			        var namegetConst = $(".lineTr").eq(i).find($(".nameSear")).html();
			        textbar == namegetConst && true ? $(".lineTr").hide() && $(".lineTr").eq(i).show() : console.log(namegetConst);
			        //if (i = $(".lineTr").length-1 && !textbar == namegetConst) { alert("Wrong context input,please check out!") };
			    };
			});
            //noSearch bar function
			$("#noSear").click(function () {
			    var textbar = $(this).siblings($(".textbar")).val();
			    /*succeed get value*/
			    console.log(textbar);
			    var nameBlock = $(".lineTr").children($(".noSear"));
			    console.log($(nameBlock).text());
			    console.log($(nameBlock).html());
			    for (var i = 0; i < $(".lineTr").length ; i++) {
			        var namegetConst = $(".lineTr").eq(i).find($(".noSear")).html();
			        textbar == namegetConst && true ? $(".lineTr").hide() && $(".lineTr").eq(i).show() : console.log(namegetConst);
			    };
			});
        })
        
        function deleteSta(id){
        	$.ajax({
                type: "Post",
                url: "/hr_doc/servlet/StaffServlet",
                data: {
               	 Command:"delete",
               	 id:id
                },
                async: false,
                dataType: "json",
                success: function (d) {
					console.log(d);
	               	if(d.code == 1){
	               		alert(d.result);
	               		location.href = "/hr_doc/subPage/staffRecord.html";
	               	}else{
	               		alert(d.error);
	               	}
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                	
                }
            });
        }


    </script>
</body>
</html>